package com.fenghongzhang.day012;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.View;


public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";
    private MyReceiver1 myReceiver1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        //动态注册一个广播接收者
//        myReceiver1 = new MyReceiver1();
//        IntentFilter intentFilter = new IntentFilter();
//        intentFilter.addAction("com.feng");
//        registerReceiver(myReceiver1,intentFilter);
    }

    public void btn(View view) {
        Intent intent = new Intent();
        intent.setAction(Const.COM_FENG);
        Bundle bundle = new Bundle();
        bundle.putString("name","大明");
        intent.putExtras(bundle);
//        sendBroadcast(intent);
        //有序广播
        sendOrderedBroadcast(intent,null);
    }

    public void btn1(View view) {
        Intent intent = new Intent();
        intent.setAction(Const.COM_FENG);
        Bundle bundle = new Bundle();
        bundle.putString("name1","小明");
        intent.putExtras(bundle);
        sendBroadcast(intent);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //注销
        unregisterReceiver(myReceiver1);
    }
}
